package com.frank.oj.controller.admin;

import com.frank.oj.common.result.CommonResult;
import com.frank.oj.model.dto.SwitchConfigDTO;
import com.frank.oj.service.admin.system.ConfigService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author frank
 * @Date 2024/3/31
 */
@RestController
@RequestMapping("/api/admin/switch")
@RequiresPermissions("system_info_admin")
public class SwitchController {

    @Resource
    private ConfigService configService;

    @GetMapping("/info")
    public CommonResult<SwitchConfigDTO> getSwitchConfig() {
        return CommonResult.successResponse(configService.getSwitchConfig());
    }

    @PutMapping("/update")
    public CommonResult<Void> setSwitchConfig(@RequestBody SwitchConfigDTO configDTO){

        try {
            configService.setSwitchConfig(configDTO);
            return CommonResult.successResponse();
        } catch (Exception e) {
            return CommonResult.errorResponse(e.getMessage());
        }
    }
}
